function setCookie(key, value, day) {
    if (day) {   // 有效期

        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = key + "=" + encodeURIComponent(value) + ";expires=" + date.toUTCString() + ";path=/";
    } else {  // 浏览器会话结束
        document.cookie = key + "=" + encodeURIComponent(value) + ";path=/";
    }
}

function getCookie(key) {
    var cookie = document.cookie;
    if (cookie) {
        var dataList = cookie.split("; ");
        for (var i = 0; i < dataList.length; i++) {
            var str = dataList[i];
            var name = str.split("=")[0];
            var val = str.split("=")[1];
            if (key == name) {
                return decodeURIComponent(val);
            }
        }
    }
    return "";
}